package proxyTest.client;

import io.netty.channel.Channel;
import io.netty.channel.EventLoop;
import io.netty.util.concurrent.ScheduledFuture;

import java.util.concurrent.TimeUnit;

/**
 * @Author: jia
 * @Descirption:
 * @Date: 2018/5/16 14:05
 * @Modified By:
 */


public class ClientStarter {
    public static void main(String[] args) {
        Client c = new Client("localhost", 10101);
        c.send("你好，我是客户端！");
        //testEventLoop(c);
    }

    //测试任务调度，六十秒之后执行任务
    private static void testEventLoop(Client c) {
        Channel channel = c.getChannel();
        //获取该channel的eventLoop
        EventLoop loop = channel.eventLoop();
        //分配一个任务，一个Runnable对象就是一个任务
        loop.schedule(new Runnable() {
            @Override
            public void run() {
                System.out.println("六十秒之后执行。。");
            }
        },60, TimeUnit.SECONDS);
    }

    //每间隔六十秒执行一次
    private static void testEventLoop2(Client c){
        Channel channel = c.getChannel();
        ScheduledFuture<?> f = channel.eventLoop().scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                System.out.println("执行。。。。");
            }
        }, 60, 60, TimeUnit.SECONDS);
        //取消任务
        f.cancel(false);
    }

}
